home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12928 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.programming,comp.sys.sgi.misc,comp.lang.c
  4. Subject: Re: C pointer question.
  5. Date: 3 Apr 1996 07:44:05 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4ju6c5INN2ee@keats.ugrad.cs.ubc.ca>
  8. References: <315BFDBB.773C@wight.hursley.ibm.com> <4jlhpl$i3c@hn.ocbbs.gen.nz> <31616BAF.5BAB@datalytics.com> <3162659B.6201@wight.hursley.ibm.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <3162659B.6201@wight.hursley.ibm.com>,
  12. Max Waterman  <dwater@wight.hursley.ibm.com> wrote:
  13. >Ie what are the arguments for :
  14. >
  15. >char    name1,
  16. >    name2,
  17. >    name3;
  18. >
  19. >over :
  20. >
  21. >char name1;
  22. >char name2;
  23. >char name3;
  24. >
  25. >?
  26. >
  27. >Aren't they identical?
  28. >
  29. >Any compiler boffs out there know about this?
  30.  
  31. These are identical. But if you put too many declarators onto one declaration
  32. specifier string, an ANSI-compliant compiler may fail, because the standard
  33. says that a compiler is only required to process declarations that have at
  34. least 12 (AFAIR) declarators (if I interpreted the confusing paragraph
  35. correctly: I'm sure this article will be followed up with some clarifications
  36. and/or flames). This might be intended as a relief to parsers that build n-ary
  37. trees, where the number of children that a parse tree node can have is a fixed
  38. array contained in the node data structure:
  39.  
  40.     #define NUM_CHILD 15
  41.  
  42.     /*
  43.      .
  44.      .
  45.      */
  46.  
  47.     struct parse_node {
  48.         /* bunch of fields */
  49.         struct parse_node child[NUM_CHILD];
  50.     };
  51.  
  52. Other than that, there is no difference. It's a matter of style. I'd tend to
  53. put _related_ variables onto one declaration specifier. For example, if I had
  54. an i and a j that were both indices into the same array, I would say:
  55.  
  56.     int i, j;    /* these are indices into array foo[]    */
  57.  
  58. but if they were unrelated, I might put them in separate declarations:
  59.  
  60.     int i;        /* this is an index into array foo[]    */
  61.     int n;        /* number of bytes from fread()        */
  62.  
  63. -- 
  64.  
  65.